package ru.spb.osll.myfit.common;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

import java.io.Serializable;

@XStreamAlias("suiteProgressCounts")
public class SuiteProgressCounts implements Serializable, ProgressCounts {
  private static final long serialVersionUID = -8868202742461450635L;

  @XStreamAlias("passed")
  @XStreamAsAttribute
  private int m_passed;

  @XStreamAlias("failed")
  @XStreamAsAttribute
  private int m_failed;

  @XStreamAlias("total")
  @XStreamAsAttribute
  private int m_total;

  public SuiteProgressCounts() {
    initialize();
  }

  private void initialize() {
    m_passed = 0;
    m_failed = 0;
    m_total = 0;
  }

  public SuiteProgressCounts(SuiteProgressCounts counts) {
    m_passed = counts.getPassed();
    m_failed = counts.getFailed();
    m_total = counts.getTotal();
  }

  public void setCounts(SuiteProgressCounts counts) {
    m_passed = counts.getPassed();
    m_failed = counts.getFailed();
    m_total = counts.getTotal();
  }

  public SuiteProgressCounts getCounts() {
    return new SuiteProgressCounts(this);
  }

  public int getPassed() {
    return m_passed;
  }

  public int getFailed() {
    return m_failed;
  }

  public int getTotal() {
    return m_total;
  }
  
  public int incrementPassed() {
    ++m_passed;
    return m_passed;
  }
  
  public int incrementFailed() {
    ++m_failed;
    return m_failed;
  }
  
  public void setTotal(int total) {
    m_total = total;
  }

  public int getProgress() {
    return m_passed + m_failed;
  }

  public void reset() {
    initialize();
  }

  @Override
  public double getPercentage() {
    return (double)(m_passed + m_failed) / m_total;
  }
}
